package org.jeecg.modules.utils;

import org.jeecg.modules.constant.BikeConstant;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

@Component
public class CostUtils {

    /**
     * 相差时间转时分秒
     *pickTime 借车时间
     *stopTime 还车时间
     * */

    public static long getSecond(long pickTime, long stopTime){
        //从对象中拿到时间
        long diff=(stopTime-pickTime)/1000;
        return diff;
    }
    public static String getUseTime(Date pickTime, Date stopTime){
        return HHmmss(pickTime.getTime()-stopTime.getTime());
    }

    /**
     * 毫秒转换时分秒   非24小时制
     * */
    public static String HHmmss(long time){
        long hours = time / (1000 * 60 * 60);
        long minutes = (time-hours*(1000 * 60 * 60 ))/(1000* 60);
        long second = time/1000%60;
        String h = "";
        String m = "";
        String s = "";
        if (hours<10){
            h="0"+hours;
        }else {
            h=""+hours;
        }
        if (minutes<10){
            m="0"+minutes;
        }else {
            m=""+minutes;
        }
        if (second<10){
            s="0"+second;
        }else {
            s=""+second;
        }
        return h+":"+m+":"+s;
    }
    /**
     * 毫秒转换时分秒   非24小时制
     * */
    public static String NewHHmm(long time){
        long hours = time / (1000 * 60 * 60);
        long minutes = (time-hours*(1000 * 60 * 60 ))/(1000* 60);
        long second = time/1000%60;
        String h = "";
        String m = "";
        String s = "";
        if (hours<10){
            if (hours!=0){
                h=hours+"小时";
            }
        }else {
            h=hours+"小时";
        }
        if (minutes<10){
            if (minutes!=0){
                m=minutes+"分钟";
            }else {
                if (hours==0||second==0){
                    m="1分钟";
                }
            }
        }else {
            m=minutes+"分钟";
        }

        return h+m;
    }
    /**
     * 秒转换分秒
     * */
    public static String MMss(long time){
        long minutes = time/60;
        long second = time%60;
        String m = "";
        String s = "";
        if (minutes<10){
            m="0"+minutes;
        }else {
            m=""+minutes;
        }
        if (second<10){
            s="0"+second;
        }else {
            s=""+second;
        }
        return m+":"+s;
    }
    public static String getValidDateStr(Date data) {
        String sDate = "";
        SimpleDateFormat sdf1 = new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy", Locale.UK);

        Date date = null;
        try {
            date = sdf1.parse(sdf1.format(data));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
        sDate = sdf.format(date);

        return sDate;
    }

}
